package com.turman.plyopengl.programs

import android.content.Context
import android.opengl.GLES20
import com.turman.plyopengl.ShaderHelper
import com.turman.plyopengl.readStringFromRaw

abstract class ShaderProgram(context: Context, vertexShaderResId: Int, fragmentShaderResId: Int) {
    protected val programId: Int

    init {
        with(context) {
            programId = ShaderHelper.buildProgram(
                readStringFromRaw(vertexShaderResId),
                readStringFromRaw(fragmentShaderResId)
            )
        }
    }

    fun getAttribLocation(name:String):Int = GLES20.glGetAttribLocation(programId,name)

    fun getUniformLocation(name:String):Int = GLES20.glGetUniformLocation(programId,name)

    fun useProgram() {
        GLES20.glUseProgram(programId)
    }
}